# Contributor: wener <wenermail@gmail.com>
# Maintainer: wener <wenermail@gmail.com>
pkgname=n2n
pkgver=3.0
pkgrel=0
pkgdesc="Peer-to-peer VPN"
url="https://github.com/ntop/n2n"
arch="all"
license="GPL-3.0-only"
makedepends="cmake openssl1.1-compat-dev libcap-dev"
install="$pkgname.pre-install"
subpackages="$pkgname-openrc $pkgname-doc"
source="https://github.com/ntop/n2n/archive/$pkgver/n2n-$pkgver.tar.gz
	supernode.initd
	supernode.confd
	edge.initd
	edge.confd
	"
# source do not contain check
options="!check"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	cmake -B build \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		$CMAKE_CROSSOPTS .
	make -C build
}

package() {
	make -C build DESTDIR="$pkgdir" install

	install -m644 -D "$builddir"/packages/etc/n2n/supernode.conf.sample "$pkgdir"/etc/n2n/supernode.conf
	install -m644 -D "$builddir"/packages/etc/n2n/edge.conf.sample "$pkgdir"/etc/n2n/edge.conf
	install -m755 -D "$srcdir"/supernode.initd "$pkgdir"/etc/init.d/supernode
	install -m644 -D "$srcdir"/supernode.confd "$pkgdir"/etc/conf.d/supernode
	install -m755 -D "$srcdir"/edge.initd "$pkgdir"/etc/init.d/edge
	install -m644 -D "$srcdir"/edge.confd "$pkgdir"/etc/conf.d/edge

}

sha512sums="
4e3806eacd7bd6de8e1818e2e42b285a12389d4423d3048c9a19f9e3aec8a6ddea276869e2dee367ea4df4711c2c4bf1b99d7fc7381b2a4773866a75a1306704  n2n-3.0.tar.gz
99ecfb3b26cd669a72cb65e374b3c39cc21dec6971b935952b75ea2cb237b201872f1764362530405cd439dc65c771e96e33f7756f4ca2f786dc4722a0a533b5  supernode.initd
df2eff2cdf11e233d187c52a7dcb039aebaa3b87ef6a12449955097bc5c17c65e4b8241e8700bdbb7d186548c4cc8d99f9cb51ba017a9f71cc8483270fa2ff4d  supernode.confd
de226f5e35d4e9955364393d855f95dc2abd770edbbcef02a8b3e7802d26ae812a1df0750497d616cd450f9bb154f54e73345f753d64124155140267207ea68b  edge.initd
2b96db736ecb5e636c44c4230671ca84175c90d19586967aa272bd7cf785126223a1fa2938b66a016b61a917aafcc20d9047d7109d40fb912e89ca3de24ae243  edge.confd
"
